package com.ushine.web.component.design.strategy.context;

import com.ushine.web.component.design.chain.salary.model.SalaryCalculateBO;
import com.ushine.web.component.design.chain.salary.model.SalaryDO;
import com.ushine.web.component.design.strategy.strategy.AbstractSalaryStrategy;
import com.ushine.web.component.exception.ServiceException;
import com.ushine.web.component.exception.ServiceExceptionEnum;

import java.math.BigDecimal;

/**
 * @Author: yls
 * @Date: 2022/03/04 14:40
 * @Description: 薪资计算环境类
 * @Version 1.0
 */
public class SalaryContext {

    /**
     * 薪资计算策略类
     */
    private AbstractSalaryStrategy abstractSalaryStrategy;

    public void setAbstractSalaryStrategy(AbstractSalaryStrategy abstractSalaryStrategy) {
        this.abstractSalaryStrategy = abstractSalaryStrategy;
    }


    /**
     * 功能描述:
     * 〈 计算具体的薪资细节 〉
     *
     * @param salaryCalculate 薪资计算的具体调用方法
     * @return : void
     * @author : yls
     * @date : 2022/3/9 14:39
     * @throws ServiceException 服务端自定义异常
     */
    public void getSalaryCalculate(SalaryCalculateBO salaryCalculate) throws ServiceException {
        SalaryDO salary = salaryCalculate.getSalaryDO();
        if (salary == null) {
            throw new ServiceException(ServiceExceptionEnum.SALARY_CALCULATE_NULL_POINTER);
        }
        // 绩效
        BigDecimal achievement = abstractSalaryStrategy.getAchievement(salaryCalculate);
        salary.setMeritPay(achievement);

        // 基础薪资
        BigDecimal baseSalary = abstractSalaryStrategy.getBaseSalary(salaryCalculate);
        salary.setBasePay(baseSalary);

        // 增值税
        BigDecimal valueAddedTax = abstractSalaryStrategy.getValueAddedTax(salaryCalculate);
        salary.setAddedValueTax(valueAddedTax);

        // 设值
        salaryCalculate.setSalaryDO(salary);
    }
}
